package eip.chapter7.contentrouter.impl;

import org.apache.log4j.Logger;
import org.jibx.runtime.JiBXException;
import org.mule.extras.client.MuleClient;
import org.mule.umo.UMOException;

import eip.chapter7.contentrouter.HotelBooking;
import eip.chapter7.contentrouter.HotelBookingDispatcher;
import eip.chapter7.contentrouter.util.JiBXHelper;

public class HotelBookingDispatcherImpl implements HotelBookingDispatcher {

	private static final Logger logger = Logger.getLogger(HotelBookingDispatcherImpl.class);
	private String target;
	
	public void dispatchBooking(HotelBooking booking) {
		try {
			String message = JiBXHelper.createBookinginXML(booking); 
			MuleClient client = new MuleClient();
			if(logger.isInfoEnabled()) {
				logger.info("Sending message " + message + " to " + target);
			}
			client.dispatch(target, message, null);
		} catch (UMOException umoE) {
			logger.error("Error sending message to target: " + target, umoE);
		} catch (JiBXException jibxExc) {
			logger.error("Error creating XML message", jibxExc);
		}
	}
	

	//---------------------------------------------
	// Simple setters and getters
	//---------------------------------------------

	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

}
